// ==UserScript==
// @name         搞定设计(屏蔽水印、会员小提示)，可下载PDF格式！！
// @version      1.0.0
// @icon        http://dynamic-image.bear20.com/640x267/uploadImages/2020/289/34/9DTKT3Y2XR06.jpg
// @require      http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js
// @require      http://hubzyy.gitee.io/link/youhou/print.js
// @match        *://*.gaoding.com/design?id=*
// @match        *://*.chuangkit.com/design?id=*

// ==/UserScript==

// // @require      http://hubzyy.gitee.io/link/youhou/gaoding.js
(function () {
    $(window).on('load', function () {
    var windowUrl = window.location.href;
    var GdurlReg = /gaoding.com\/design\?id=/;
    var CkturlReg = /chuangkit.com\/design\?d=/;
    var GddiyCss = `
        .editor-watermark,
        .editor-remove-watermark,
        .remove-watermark,
        .icon-vip-diamond,
        .gdd-material-card__vip,
        .g-popover__container:nth-child(2),
        #svePdf
        { display:none;}
        .eui-buttons-bar--dropdown > button:nth-child(1),
        .eui-buttons-bar--dropdown > button:nth-child(2)
        {pointer-events:none;}
        .eui-buttons-bar--dropdown{cursor: pointer;}
`
    var CktdiyCss = `
        .templateWaterMark,
        .remove-cktTemplate-watermark,
        #svePdf
        { display:none;}
        .design-header-download-span-newDown,
        .design-header-download-left-download
        {pointer-events:none;}
`
    function addStyle(name) {
        $(document).ready(function () {
            var style = document.createElement('style');
            style.innerHTML = name;
            $('body').append(style);
        });
    }
    function yes(contentID,DownloadBut) {
        var divHtml = '<button type="button" id="svePdf"></button>'

        setTimeout(function () {
        $(DownloadBut).append(divHtml)
            $(DownloadBut).on('click', function () {
                
                var diyPrtCss = `@media print {
            @page {
            size: `+ $(contentID).width() + `px ` + $(contentID).height() + `px;
            margin: 0;
            }
            body {
                margin: 0;
              }
        });`
                var prtStyle = document.createElement('style');
                prtStyle.innerHTML = diyPrtCss;
                $('body').append(prtStyle);
                $(contentID).print({
                    globalStyles: true,//是否包含父文档的样式，默认为true
                    mediaPrint: false,//是否包含media='print'的链接标签。会被globalStyles选项覆盖，默认为false
                    stylesheet: null,//外部样式表的URL地址，默认为null
                    noPrintSelector: ".no-print",//不想打印的元素的jQuery选择器，默认为".no-print"
                    iframe: true,//是否使用一个iframe来替代打印表单的弹出窗口，true为在本页面进行打印，false就是说新开一个页面打印，默认为true
                    append: null,//将内容添加到打印内容的后面
                    prepend: null,//将内容添加到打印内容的前面，可以用来作为要打印内容
                    deferred:
                        $.Deferred()//回调函数
                });
            })

        }, 2000)
    }
    if (GdurlReg.test(windowUrl)) {
        addStyle(GddiyCss)
        yes('.editor-canvas','.editor-right-actions > .eui-buttons-bar--dropdown')
    } else if (CkturlReg.test(windowUrl)) {
        addStyle(CktdiyCss)
        yes('#page','.design-header-download-newDown')
    }
})
})()